<!--
 * @Author: 施伟略
 * @Date: 2020-06-29 13:42:57
 * @LastEditTime: 2020-07-02 17:43:33
 * @LastEditors: Please set LastEditors
 * @Description: 搜索结果
 * @FilePath: \jkShop\shop\src\pages\help\components\searchResult.vue
--> 
<template>
  <div class="searchResult">
    <!-- 顶部导航 -->
    <van-nav-bar title="搜索结果" left-text="返回" left-arrow @click-left="onClickLeft" />
    <!-- 搜索 -->
    <van-search background="#f4f4f4" v-model="val" placeholder="输入问题关键词" />
    <van-divider />
    <!-- 搜索结果统计 -->
    <div class="total">{{'共'+filterData.length+'个搜索结果'}}</div>
    <!-- 搜索结果显示 -->
    <ul class="ul-content">
      <li class="li-content" v-for="(item,idx) of filterData" :key="idx">
        <router-link :to="{path:'/questionDetails',query:{id:item.id}}">
          <span>></span>
          {{item.title}}
        </router-link>
      </li>
    </ul>
  </div>
</template>

<script>
import * as api from "@/api/apiList/help/help.js";
export default {
  props: ["val"], //路由中传递的关键字数据
  data() {
    return {
      datas: [] //  全部问题数据
    };
  },
  methods: {
    // 返回上一页
    onClickLeft() {
      this.$router.go(-1);
    },
    // 获取帮助中心数据
    async API_question(title, page = 1, limit = 10) {
      let result = {
        title,
        page,
        limit
      };
      return await api.help(result);
    }
  },
  computed: {
    // 根据关键字过滤，得到过滤后的跟关键字相关的数据
    filterData() {
      return this.datas.filter(value => value.title.indexOf(this.val) !== -1);
    }
  },
  async created() {
    let res = await this.API_question();
    this.datas = res.data.data;
    // console.log(this.datas);
  }
};
</script>

<style lang="scss" scoped>
@import "@/style/help/help.scss"
</style>